1 const assert
= require( 'assert' ),
2 HistoryPage
= require( '../pageobjects/history.page' ),
3 UserLoginPage
= require( 'wdio-mediawiki/LoginPage' ),
4 Util
= require( 'wdio-mediawiki/Util' );
6 describe( 'Rollback with confirmation', function () {
11 // disable VisualEditor welcome dialog
12 browser
.deleteCookie();
14 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
16 // Enable rollback confirmation for admin user
17 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
18 UserLoginPage
.loginAdmin();
21 browser
.execute( function () {
22 return ( new mw
.Api() ).saveOption(
23 'showrollbackconfirmation',
29 beforeEach( function () {
30 browser
.deleteCookie();
32 content
= Util
.getTestString( 'beforeEach-content-' );
33 name
= Util
.getTestString( 'BeforeEach-name-' );
35 HistoryPage
.vandalizePage( name
, content
);
37 UserLoginPage
.loginAdmin();
38 HistoryPage
.open( name
);
41 it( 'should offer rollback options for admin users', function () {
42 assert
.strictEqual( HistoryPage
.rollback
.getText(), 'rollback 1 edit' );
44 HistoryPage
.rollback
.click();
46 assert
.strictEqual( HistoryPage
.rollbackConfirmable
.getText(), 'Rollback of one edit?' );
47 assert
.strictEqual( HistoryPage
.rollbackConfirmableYes
.getText(), 'Rollback' );
48 assert
.strictEqual( HistoryPage
.rollbackConfirmableNo
.getText(), 'Cancel' );
51 it( 'should offer a way to cancel rollbacks', function () {
52 HistoryPage
.rollback
.click();
53 HistoryPage
.rollbackConfirmableNo
.click();
57 assert
.strictEqual( HistoryPage
.heading
.getText(), 'Revision history of "' + name
+ '"' );
60 it( 'should perform rollbacks after confirming intention', function () {
61 HistoryPage
.rollback
.click();
62 HistoryPage
.rollbackConfirmableYes
.click();
64 // waitUntil indirectly asserts that the content we are looking for is present
65 browser
.waitUntil( function () {
66 return browser
.getText( '#firstHeading' ) === 'Action complete';
67 }, 5000, 'Expected rollback page to appear.' );
70 it( 'should verify rollbacks via GET requests are confirmed on a follow-up page', function () {
71 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
72 browser
.url( rollbackActionUrl
);
74 browser
.waitUntil( function () {
75 return HistoryPage
.rollbackNonJsConfirmable
.getText() === 'Revert edits to this page?';
76 }, 5000, 'Expected rollback confirmation page to appear for GET-based rollbacks.' );
78 HistoryPage
.rollbackNonJsConfirmableYes
.click();
80 browser
.waitUntil( function () {
81 return browser
.getText( '#firstHeading' ) === 'Action complete';
82 }, 5000, 'Expected rollback page to appear.' );
87 describe( 'Rollback without confirmation', function () {
92 // disable VisualEditor welcome dialog
93 browser
.deleteCookie();
95 browser
.localStorage( 'POST', { key
: 've-beta-welcome-dialog', value
: '1' } );
97 // Disable rollback confirmation for admin user
98 // Requires user to log in again, handled by deleteCookie() call in beforeEach function
99 UserLoginPage
.loginAdmin();
101 browser
.pause( 300 );
102 browser
.execute( function () {
103 return ( new mw
.Api() ).saveOption(
104 'showrollbackconfirmation',
110 beforeEach( function () {
111 browser
.deleteCookie();
113 content
= Util
.getTestString( 'beforeEach-content-' );
114 name
= Util
.getTestString( 'BeforeEach-name-' );
116 HistoryPage
.vandalizePage( name
, content
);
118 UserLoginPage
.loginAdmin();
119 HistoryPage
.open( name
);
122 it( 'should perform rollback via POST request without asking the user to confirm', function () {
123 HistoryPage
.rollback
.click();
125 // waitUntil indirectly asserts that the content we are looking for is present
126 browser
.waitUntil( function () {
127 return HistoryPage
.headingText
=== 'Action complete';
128 }, 5000, 'Expected rollback page to appear.' );
131 it( 'should perform rollback via GET request without asking the user to confirm', function () {
132 var rollbackActionUrl
= HistoryPage
.rollbackLink
.getAttribute( 'href' );
133 browser
.url( rollbackActionUrl
);
135 browser
.waitUntil( function () {
136 return browser
.getText( '#firstHeading' ) === 'Action complete';
137 }, 5000, 'Expected rollback page to appear.' );